package com.gtw;

import com.foxinmy.weixin4j.mp.WeixinProxy;
import com.foxinmy.weixin4j.payment.WeixinPayProxy;
import com.github.tobato.fastdfs.FdfsClientConfig;
import com.gtw.config.HeadersCORSFilter;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;

/**
 * @author wuye
 */
@Import(FdfsClientConfig.class)
@SpringBootApplication
public class GtwApplication extends SpringBootServletInitializer {

	public GtwApplication() {
		setRegisterErrorPageFilter(false);
	}

	public static void main(String[] args) {
		SpringApplication.run(GtwApplication.class, args);
	}

	@Bean
	public WeixinProxy weixinProxy() {
		return new WeixinProxy();
	}

	@Bean
	public WeixinPayProxy weixinPayProxy() {
		return new WeixinPayProxy();
	}

	@Override
	protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
		return application.sources(GtwApplication.class);
	}

	@Bean
	public FilterRegistrationBean testFilterRegistration() {
		FilterRegistrationBean registration = new FilterRegistrationBean();
		registration.setFilter(new HeadersCORSFilter());
		registration.addUrlPatterns("/*");
		registration.setName("HeadersCORSFilter");
		registration.setOrder(1);
		return registration;
	}
}
